<?php
/**
 * Created by PhpStorm.
 * User: zoupeng
 * Date: 2018/9/8
 * Time: 上午1:10
 */

namespace app\admin\model;

use think\Exception;
use think\Log;
use think\Model;

class ShoppingGuideCollect extends Model
{
    /**
     * @Notes:   分页查询数据
     * @User:    this邹
     * @CreateDate:  2019/2/27 0027 16:46
     * @return \think\Paginator
     */
    public function findShoppingGuideList()
    {
        try {
            $shoppingGuideList = $this->alias('SG')->join('category C', 'C.id=SG.cid')->field('SG.*,C.name as categoryName')->paginate(20);
            return $shoppingGuideList;
        } catch (Exception $e) {
            Log::write('查询ShoppingGuideCollect数据异常' . $e->getMessage(), 'error');
        }
    }

    /**
     * 根据主键自增ID获取信息
     * @param $id 主键自增ID
     * @return array|false|\PDOStatement|string|Model
     */
    public function getShoppingGuideById($id){
        try{
            $shoppingGuide = $this->find($id);
            return $shoppingGuide;
        }catch (Exception $e){
            Log::write('查询getShoppingGuideById数据异常' . $e->getMessage(), 'error');
        }
    }

    /**
     * 新增数据
     * @param $data
     * @return int|string
     */
    public static function add($data)
    {
        try {
            $id = self::insertGetId($data);
        } catch (Exception $exception) {
            return 0;
        }
        return $id;
    }

    /**
     * 修改数据
     * @param $data
     * @return int|string
     */
    public static function editShoppingGuide($data)
    {
        try {
            $id = self::update($data);
        } catch (Exception $exception) {
            return 0;
        }
        return $id;
    }

    /**
     * 删除数据--单个
     * @param $id
     * @return int
     */
    public static function del($id)
    {
        try {
            $id = self::where('id', $id)->delete();
        } catch (Exception $exception) {
            return 0;
        }
        return $id;
    }

    /**
     * 删除数据--批量
     * @param $ids
     * @return int
     */
    public static function delss($ids)
    {
        try {
            $id = self::destroy($ids);
        } catch (Exception $exception) {
            return 0;
        }
        return $id;
    }
}